package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.SubwayStartItemBean;

/**
 * Created by zhangxutong .
 * Date: 16/08/28
 */

public class CityAdapter extends RecyclerView.Adapter<CityAdapter.ViewHolder> {
    protected Context mContext;
    protected List<SubwayStartItemBean> mDatas;
    protected LayoutInflater mInflater;
    private MoreInterface moreInterface;

    public interface MoreInterface {
        public void onClick(View view, int position);
    }

    public void moreOnClick(MoreInterface moreInterface) {
        this.moreInterface = moreInterface;
    }


    public CityAdapter(Context mContext, List<SubwayStartItemBean> mDatas) {
        this.mContext = mContext;
        this.mDatas = mDatas;
        mInflater = LayoutInflater.from(mContext);
    }

    public List<SubwayStartItemBean> getDatas() {
        return mDatas;
    }

    public CityAdapter setDatas(List<SubwayStartItemBean> datas) {
        mDatas = datas;
        return this;
    }

    @Override
    public CityAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mInflater.inflate(R.layout.item_city, parent, false));
    }

    @Override
    public void onBindViewHolder(final CityAdapter.ViewHolder holder, final int position) {
        final SubwayStartItemBean cityBean = mDatas.get(position);
        String siteName = cityBean.getTitle();
        TextView mark1 = holder.mark1;
        TextView mark2 = holder.mark2;
        mark1.setVisibility(View.GONE);
        mark2.setVisibility(View.GONE);
        if (siteName.equals("广济南路")) {
            mark1.setVisibility(View.VISIBLE);
            mark2.setVisibility(View.VISIBLE);
            mark1.setText("1");
            mark1.setBackground(mContext.getResources().getDrawable(R.drawable.circle_subway_one));
            mark2.setText("2");
            mark2.setBackground(mContext.getResources().getDrawable(R.drawable.circle_subway_two));
        }

        if (siteName.equals("乐桥")) {
            mark1.setVisibility(View.VISIBLE);
            mark2.setVisibility(View.VISIBLE);
            mark1.setText("1");
            mark1.setBackground(mContext.getResources().getDrawable(R.drawable.circle_subway_one));
            mark2.setText("4");
            mark2.setBackground(mContext.getResources().getDrawable(R.drawable.circle_subway_four));
        }

        if (siteName.equals("苏州火车站") || siteName.equals("石湖东路")) {
            mark1.setVisibility(View.VISIBLE);
            mark2.setVisibility(View.VISIBLE);
            mark1.setText("4");
            mark1.setBackground(mContext.getResources().getDrawable(R.drawable.circle_subway_four));
            mark2.setText("2");
            mark2.setBackground(mContext.getResources().getDrawable(R.drawable.circle_subway_two));
        }

        if (siteName.equals("红庄")) {
            mark1.setVisibility(View.VISIBLE);
            mark1.setText("4");
            mark1.setBackground(mContext.getResources().getDrawable(R.drawable.circle_subway_four));
        }

        if (siteName.equals("宝带路")) {
            mark1.setVisibility(View.VISIBLE);
            mark1.setText("4");
            mark1.setBackground(mContext.getResources().getDrawable(R.drawable.circle_subway_four));
            mark2.setVisibility(View.VISIBLE);
            mark2.setText("2");
            mark2.setBackground(mContext.getResources().getDrawable(R.drawable.circle_subway_three));
        }
        if (siteName.equals("东方之门")) {
            mark1.setVisibility(View.VISIBLE);
            mark1.setText("3");
            mark1.setBackground(mContext.getResources().getDrawable(R.drawable.circle_subway_three));
            mark2.setVisibility(View.VISIBLE);
            mark2.setText("1");
            mark2.setBackground(mContext.getResources().getDrawable(R.drawable.circle_subway_one));
        }
        if (siteName.equals("盘蠡路")) {
            mark1.setVisibility(View.VISIBLE);
            mark1.setText("3");
            mark1.setBackground(mContext.getResources().getDrawable(R.drawable.circle_subway_three));
            mark2.setVisibility(View.VISIBLE);
            mark2.setText("2");
            mark2.setBackground(mContext.getResources().getDrawable(R.drawable.circle_subway_two));
        }
        if (siteName.equals("狮子山")) {
            mark1.setVisibility(View.VISIBLE);
            mark1.setText("3");
            mark1.setBackground(mContext.getResources().getDrawable(R.drawable.circle_subway_three));
            mark2.setVisibility(View.VISIBLE);
            mark2.setText("1");
            mark2.setBackground(mContext.getResources().getDrawable(R.drawable.circle_subway_one));
        }

        holder.tvCity.setText(cityBean.getTitle());
        holder.content.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (moreInterface != null) {
                    moreInterface.onClick(view, position);
                }
            }
        });



        holder.avatar.setImageResource(R.drawable.more);
    }

    @Override
    public int getItemCount() {
        return mDatas != null ? mDatas.size() : 0;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvCity;
        ImageView avatar;
        View content;
        private final TextView mark1;
        private final TextView mark2;

        public ViewHolder(View itemView) {
            super(itemView);
            tvCity = (TextView) itemView.findViewById(R.id.tvCity);
            mark1 = (TextView) itemView.findViewById(R.id.tv_mark_1);
            mark2 = (TextView) itemView.findViewById(R.id.tv_mark_2);
            avatar = (ImageView) itemView.findViewById(R.id.ivAvatar);
            content = itemView.findViewById(R.id.content);
        }
    }
}
